package cn.com.bluemoon.daps.sync.core.sync.sql.mysql;

import cn.com.bluemoon.daps.common.datamarking.IDataMarking;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

/**
 * @author Jarod.Kong
 * @date 2021/6/28 14:17
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class MysqlImport implements IDataMarking {
    private String importFilePath;
    private MysqlConnect mysqlConnect;

    @Override
    public String toString() {
       return toString(false);
    }

    @Override
    public String toString(boolean dataMark) {
        if (mysqlConnect == null) return super.toString();
        String script = String.format("%s -h%s -P%d -u%s -p%s %s< %s",
                mysqlConnect.getScriptPath(), mysqlConnect.getHost(),
                mysqlConnect.getPort(), mysqlConnect.getUser(),
                dataMark ? "********" : mysqlConnect.getPassword(),
                StringUtils.isBlank(mysqlConnect.getDatabase()) ? "" : mysqlConnect.getDatabase(),
                importFilePath);
        return script;
    }
}